import {onBeforeUnmount, onMounted, reactive} from "vue";

export default function () {
    let point = reactive({  //必须要在这里去使用reactive
        x: 0,
        y: 0
    })

    //鼠标点击事件
    function savePoint(event) {
        point.x = event.pageX
        point.y = event.pageY
        console.log(point.x, point.y)
    }

    onMounted(() => {
        window.addEventListener('click', savePoint); //挂载时绑定
    })
    onBeforeUnmount(() => {
        window.removeEventListener('click', savePoint); //销毁前解绑
    })
    return point //将point返回出去
}